from access.core.codesnippetgenerator import CodeSnippetGenerator
from access.core.utterancegenerator import UtteranceGenerator
from third_party.active_state.recipes.autoassign import autoassign

class ProgrammingLanguage(object):
#  @autoassign
  def __init__(self,
               utterance_generator = UtteranceGenerator(),
               snippet_generator = CodeSnippetGenerator(),
               vocabulary = {},
               snippets = []):
    self.utterance_generator = utterance_generator
    self.snippet_generator = snippet_generator
    self.vocabulary = vocabulary
    self.snippets = snippets
    print 'before'
    print self.snippets
    print self.vocabulary
    self.Configure()
    print 'after'
    print self.snippets
    print self.vocabulary

  def Configure(self):
    print 'configured'
    utterance_patterns = self.DefineUtterancePatterns()
    snippet_patterns = self.DefineSnippetPatterns()

    for natural_language in utterance_patterns:
      if not self.vocabulary.has_key(natural_language):
        self.vocabulary[natural_language] = []
      for utterance_pattern in utterance_patterns[natural_language]:
        for utterance in self.utterance_generator.Generate(utterance_pattern):
          self.vocabulary[natural_language].append(utterance)

    for snippet_pattern in snippet_patterns:
      for snippet in self.snippet_generator.Generate(snippet_pattern):
        self.snippets.append(snippet)
        
    pass

  def DefineUtterancePatterns(self):
    return {}
  
  def DefineSnippetPatterns(self):
    return {}
  
  def __repr__(self):
    return '\n'.join(['{self.__module__}.{self.__class__.__name__}(',
                      'vocabulary={self.vocabulary}, ',
                      'snippets={self.snippets})']).format(self = self)
    